<?php

use app\api\middleware\CrossDomain;
use Webman\Route;

Route::post('/api/auth/login', [app\api\controller\AuthController::class, 'login']);
Route::post('/api/auth/refresh', [app\api\controller\AuthController::class, 'refresh']);

Route::group('/api', function () {
    Route::get('/dashboard', [app\api\controller\IndexController::class, 'dashboard']);

    // 用户认证相关路由
    Route::group('/auth', function () {
        Route::post('/logout', [app\api\controller\AuthController::class, 'logout']);
    });

    // 客户管理相关路由
    Route::group('/customer', function () {
        Route::get('/list', [app\api\controller\CustomerController::class, 'lists']);
        Route::post('/create', [app\api\controller\CustomerController::class, 'create']);
        Route::post('/update', [app\api\controller\CustomerController::class, 'update']);
        Route::get('/info', [app\api\controller\CustomerController::class, 'customerInfo']);
        Route::get('/detail', [app\api\controller\CustomerController::class, 'customerDetail']);
        Route::post('/delete', [app\api\controller\CustomerController::class, 'delete']);
    });

    // 跟进记录相关路由
    Route::group('/follow_up', function () {
        Route::post('/create', [app\api\controller\FollowUpController::class, 'create']);
        Route::get('/list', [app\api\controller\FollowUpController::class, 'lists']);
        Route::get('/detail', [app\api\controller\FollowUpController::class, 'detail']);
        Route::post('/delete', [app\api\controller\FollowUpController::class, 'delete']);
    });

    // 通用上传
    Route::group('/upload', function () {
        Route::post('/image', [app\api\controller\UploadController::class, 'imageUpload']);
        Route::post('/files', [app\api\controller\UploadController::class, 'filesUpload']);
    });

    // 通用API
    Route::group('/common', function () {
        Route::get('/customer_fields', [app\api\controller\ApiController::class, 'getFieldGroups']);
        Route::get('/validation_rules', [app\api\controller\ApiController::class, 'getValidationRules']);
        Route::get('/region', [app\api\controller\ApiController::class, 'getRegion']);
        Route::get('/user_list', [app\api\controller\ApiController::class, 'getUserList']);
        Route::get('/profit_base', [app\api\controller\ApiController::class, 'getCompanyProfit']);
    });
})->middleware(app\api\middleware\JwtAuth::class)->middleware(CrossDomain::class);
